import isNumber from 'is-number'
import isPromise from 'is-promise'
import {
  isArray,
  isBoolean,
  isError,
  isRegExp,
  isDate,
  isString,
  isArguments,
  isFunction,
  isObject,
  isPlainObject
} from 'lodash-es'

/* eslint no-useless-escape:0 */
const reg =
  /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/

const formData = (value: any): value is FormData => {
  return Object.prototype.toString.call(value) === '[object FormData]'
}

const is = {
  array: isArray,
  number: isNumber,
  boolean: isBoolean,
  promise: isPromise,
  error: isError,
  regExp: isRegExp,
  date: isDate,
  string: isString,
  arguments: isArguments,
  func: isFunction,
  object: isObject,
  plainObject: isPlainObject,
  formData,
  url: (path: string): boolean => reg.test(path)
}

export default is
